package grp.test.controller;

import grp.test.common.ServerResponse;
import grp.test.pojo.Borrow;
import grp.test.service.IPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Chloe on 2020/8/15.
 */
@Controller
@RequestMapping("pay")
public class PayController {
    @Autowired
    private IPayService iPayService;
    //第一步，获取缴费信息，计算缴费金额
    @RequestMapping(value = "overduePay.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<Borrow> overduePay(Borrow key){
        if(key.getBookId() == null || key.getUserId()==null){
            return ServerResponse.createByErrorMessage("无法获取缴费信息！");
        }
        return iPayService.overduePay(key);
    }
    //第二步，缴费
    @RequestMapping(value = "pay.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<Double> pay(Borrow key){
        if(key.getBookId() == null || key.getUserId()==null){
            return ServerResponse.createByErrorMessage("缴费失败！");
        }
        return iPayService.pay(key);
    }
    //第三步，更新数据库缴费信息
    @RequestMapping(value = "updatePayInfo.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<Borrow> updatePayInfo(Borrow key){
        if(key.getBookId() == null || key.getUserId()==null){
            return ServerResponse.createByErrorMessage("缴费信息更新失败！");
        }
        return iPayService.updatePayInfo(key);
    }
}
